<?php
include_once("../configs/admin.config.inc.php");//--> admin global var
include_once("db.inc.php");						//--> db global var
include_once("Operation.php");					//--> Operation
include_once("PicUpload.php");					//--> PicUpload
include_once("Pic.php");						//--> Pic
include_once("InfoClass.php");					//--> InfoClass
include_once("Files.php");						//--> Files
require_once("controlHeader.php");				//--> system control header

$objOperate		= new Operation($sessionImpl->session['lan']);			//--> Operation instance
$objPicUpload	= new PicUpload($sessionImpl->session['lan'], $uid);		//--> PicUpload
$objPic			= new Pic($sessionImpl->session['lan'], $uid);			//--> Audio
$objInfoClass	= new InfoClass($sessionImpl->session['lan'], $uid);		//--> InfoClass
$objFiles		= new Files();											//--> Files

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);

if(isset($_GET['id']) && !empty($_GET['id']) && isset($_GET['formatid']) && !empty($_GET['formatid'])){
	$id 		= $_GET['id'];
	$formatid 	= $_GET['formatid'];

	$isReturn = $objPicUpload->delete($arrOperate, $id, $formatid);
	if($isReturn){
		$arrDataInfo = $objInfoClass->getFromID($arrOperate, $formatid);
		if(is_array($arrDataInfo)){
			$filepath = $objFiles->strGetFullPathByID(PIC_DOWNLOAD_DIR, $id, $id . '.' . $arrDataInfo['name']);

			if(file_exists($filepath))
				unlink($filepath);
			
		}
		
		$objPic->editStatus($arrOperate, $id, "wait");
		
		$error_message = 'delete successfully.';
	}else 
		$error_message = 'delete failure.';
}


echo "<script language='javascript'>";
echo "alert(\"$error_message\");";
echo "location.href=\"".$_SERVER['HTTP_REFERER']."\";";
echo "</script>";

//$backurl = $_SERVER['HTTP_REFERER'];
//header("Location: $backurl");
?>
